package com.learn.jdk;

import com.sun.org.apache.xerces.internal.dom.PSVIAttrNSImpl;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;

/**
 * @author: lipan
 * @date: 2021/5/18 20:59
 */

public class CompletableFutureDemo2 {


    public static void main(String[] args) {


        Executor scheduledExecutorService = Executors.newScheduledThreadPool(1, r -> {
            Thread thread = new Thread(r);
            thread.setDaemon(true);
            return thread;
        });
        //supplyAsync 有一个supllier的接口用来提供value
        CompletableFuture.supplyAsync(()->{
            try {
                Thread.sleep(3000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
           return  "hello word";
        },scheduledExecutorService).whenComplete((result,ex)->{
            System.out.println("执行结果:"+result);
            System.out.println("异常信息:"+ex.getLocalizedMessage());
        });

        ((ScheduledExecutorService) scheduledExecutorService).shutdown();




        System.out.println("执行其他逻辑");


        try {
            System.out.println(""+Thread.currentThread().getName());
            Thread.currentThread().join();
        } catch (InterruptedException e) {

        }

    }



}
